#include "AbstractPolygonMapItem.h"

void AbstractPolygonMapItem::setPoints(const QVector<QPointF>& points)
{
	m_points.clear();
	m_points.append(points);
	if (!points.isEmpty())
	{
		m_pos = points[0];
	}
}

void AbstractPolygonMapItem::addPoint(const QPointF& point)
{
	if (m_points.isEmpty())
	{
		m_pos = point;
	}
	m_points.append(point);
}

void AbstractPolygonMapItem::removePointByIndex(int index)
{
	if (index > -1 && index < m_points.count())
	{
		m_points.removeAt(index);
	}
}

void AbstractPolygonMapItem::addPoints(const QVector<QPointF> &points)
{
	m_points.append(points);
	if (!m_points.isEmpty())
	{
		m_pos = m_points[0];
	}
}

void AbstractPolygonMapItem::setPos(const QPointF &pos)
{
	auto offset = m_pos - pos;
	m_pos = pos;
	for (auto &point : m_points)
	{
		point = point - offset;
	}
}
AbstractPolygonMapItem::AbstractPolygonMapItem()
{

}

bool AbstractPolygonMapItem::alterPoint(int index, const QPointF& point)
{
	if (index < m_points.size())
	{
		m_points[index] = point;
		return true;
	}
	return false;
}
